<?php
use GRH\Helper\Text;
?>
<?php
$title = "Sites";
$this->headTitle($title);
?>
<h1><?php echo $title; ?></h1>

<div id="tabs">
    <ul>
        <li><a href="#list">Liste</a></li>
        <li><a href="#create">Création de Site</a></li>
    </ul>
    <div id='list'>
        <table>
            <thead>
                <tr>
                    <td style="min-width: 100px;">ID</td>
                    <td style="min-width: 150px;">Libellé</td>
                    <td style="min-width: 250px;">Adresse</td>
                    <td>&nbsp;</td>
                </tr>
            </thead>
            <tbody>
                <?php foreach($this->siteList as $site): ?>
                <?php 
                $urlEdit = $this->url('GRH/default', array(
                    'controller' => 'site', 
                    'action' => 'edit', 
                    'id' => $site->site_id));
                $urlDelete = $this->url('GRH/default', array(
                    'controller' => 'site',
                    'action' => 'delete',
                    'id' => $site->site_id
                ));
                ?>
                <tr>
                    <td>Site <?php echo $site->site_id; ?></td>
                    <td><a href="#" onclick="return ajaxOpenDialog('<?php echo $urlEdit; ?>', 290, 230, 'Editer <?php echo $site->libelle; ?>');"><span id='libelle-<?php echo $site->site_id ;?>'><?php echo $site->libelle; ?></span></a></td>
                    <td><a href="#" onclick="return ajaxOpenDialog('<?php echo $urlEdit; ?>', 290, 230, 'Editer <?php echo $site->libelle; ?>');"><span id='adresse-<?php echo $site->site_id ;?>'><?php echo Text::crop($site->adresse, 50); ?></span></a></td>
                    <td>
                        <a href="#" onclick="return ajaxOpenDialog('<?php echo $urlEdit; ?>', 290, 230, 'Editer <?php echo $site->libelle; ?>');">
                            <img src="<?php echo $this->basePath() .'/img/grh/edit-16x15.png' ?>" title="Editer <?php echo $site->libelle; ?>" alt="Editer">
                        </a>
                        <a href="#" onclick="return ajaxOpenDialog('<?php echo $urlDelete; ?>', 290, 230, 'Effacer <?php echo $site->libelle; ?>');">
                            <img src="<?php echo $this->basePath() .'/img/grh/delete-16x16.png' ?>" title="Effacer <?php echo $site->libelle; ?>" alt="Effacer">
                        </a>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan='10'></td>
                </tr>
            </tfoot>
        </table>
    </div>
    <div id="create">
        <?php
        $form = $this->newSite;
        $form->setAttribute('action', $this->url('GRH/default', array('controller' => 'site', 'action' => 'add')));
        $form->setAttribute('class', 'form');
        $form->prepare();
        echo $this->form()->openTag($form);
        echo $this->formHidden($form->get('site_id'));
        ?>
        <div class="form-row">
            <div class="form-element">
                <span class="form-label">Libellé</span>
                <?php echo $this->formText($form->get('libelle')); ?>
            </div>
        </div>
        <div class="row">
            <div class="form-element">
                <span class="form-label">Adresse</span>
                <?php echo $this->formTextarea($form->get('adresse')); ?>
            </div>
        </div>
        <input type="submit" value="Ajouter" class="button" style="float:right; margin-top: 10px;">
        <?php
        echo $this->form()->closeTag();
        ?>
    </div>
</div>
<style type="text/css">
    .form{
        width: 457px;
        height: 130px;
    }
    
    textarea{
        width: 248px;
    }
</style>    